import type LayerModelSimple from '../../LayerModel/LayerModelSimple'
import { GeoView } from '../../type/GeoType'
import MapUtil from '../../utils/MapUtil'
import type { Map } from 'ol'

/**
 * @ClassName OpenlayersMapUtil
 * @Description Openlayers地图工具
 * @Author xuyizhuo
 * @Date 2023/11/16 22:14
 */
export default class OpenlayersMapUtil extends MapUtil<Map> {
    /**
     * 加载地图服务
     * @returns {}
     */
    addService(): LayerModelSimple<Map> {
        return {} as LayerModelSimple<Map>
    }

    /**
     * 获取地图视角
     * @returns {}
     */
    getMapView(): GeoView {
        // 获取地图中心点和地图层级
        const view = this.realMap.getView()
        const centerPoint = view.getCenter()
        return <GeoView>{
            x: centerPoint ? centerPoint[0] : 0,
            y: centerPoint ? centerPoint[1] : 0,
            z: view?.getZoom ? view.getZoom() : 0,
        }
    }

    /**
     * 飞行到视角
     * @param {GeoView} geoView 视角信息
     * @returns {OpenlayersMapUtil}
     */
    flyToView(geoView: GeoView): OpenlayersMapUtil {
        // 设置地图中心点和层级
        const { x, y, z } = geoView
        const view = this.realMap.getView()
        view.setCenter([x, y])
        view.setZoom(z)
        return this
    }
}
